package org.esprit.ocm.client.ui.ec2;

import org.esprit.ocm.dto.impl.AwsCredentialsDto;
import org.esprit.ocm.dto.impl.ServerDto;
import org.esprit.ocm.dto.impl.UserDto;

import com.smartgwt.client.types.Overflow;
import com.smartgwt.client.types.Side;
import com.smartgwt.client.widgets.Canvas;
import com.smartgwt.client.widgets.layout.Layout;
import com.smartgwt.client.widgets.tab.Tab;
import com.smartgwt.client.widgets.tab.TabSet;

public class MainAreaEC2 extends Layout {
	private final TabSet		topTabSet	= new TabSet();

	private static MainAreaEC2	instance	= null;

	public static MainAreaEC2 getMainAreaEC2(ServerDto server, AwsCredentialsDto credentials, UserDto user) {
		if (instance == null) {
			instance = new MainAreaEC2(server, credentials, user);
		}
		return instance;
	}

	public MainAreaEC2(ServerDto server, AwsCredentialsDto credentials, UserDto user) {

		super();
		this.setOverflow(Overflow.HIDDEN);

		topTabSet.setTabBarPosition(Side.TOP);
		topTabSet.setTabBarAlign(Side.LEFT);

		addTabToTopTabset("Instances", new InstanceZone(server, credentials, user), false);
		addTabToTopTabset("Images", new ImageZone(server, credentials, user), false);
		addTabToTopTabset("KeyPairs", new KeyPairZone(server, credentials, user), false);
		addTabToTopTabset("Security Groups", new GroupZone(server, credentials, user), false);
		// addTabToTopTabset("Elastic IPs", new IpZone(), false);
		// addTabToTopTabset("Volumes and Snapshots", new VolumeZone(), false);
		// addTabToTopTabset("Availability Zones", new AvailabilityZone(server,
		// credentials, user), false);

		this.addMember(topTabSet);

	}

	private void addTabToTopTabset(String title, Canvas pane, boolean closable) {
		Tab tab = createTab(title, pane, closable);
		topTabSet.addTab(tab);
	}

	private Tab createTab(String title, Canvas pane, boolean closable) {
		Tab tab = new Tab(title);
		tab.setCanClose(closable);
		tab.setPane(pane);
		return tab;
	}

}